/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						script_simple_adjustment_action.h

	$Header: /heroes4/script_simple_adjustment_action.h $

	$NoKeywords: $

 ************************************************************************/

#if !defined( SCRIPT_SIMPLE_ADJUSTMENT_ACTION_H_INCLUDED )
#define SCRIPT_SIMPLE_ADJUSTMENT_ACTION_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "script_targeted_action.h"
#include "streambuf_operators.h"

// --------------------------------------------------------------------------
// t_script_simple_adjustment_action class template
// --------------------------------------------------------------------------

template < typename t_target_arg, typename t_adjustment_io >
class t_script_simple_adjustment_action
	:	public t_script_targeted_action< t_target_arg >
{
public:
	// Constructor
	t_script_simple_adjustment_action();

	// Member functions
	int				get_adjustment() const;
	
	virtual bool	read( std::streambuf& stream, int version );
	virtual bool	read_from_map(
						std::streambuf &	stream,
						int					format_version );
	virtual bool	write( std::streambuf& stream ) const;

protected:
	// Data members
	int	m_adjustment;
};

// --------------------------------------------------------------------------
// t_script_simple_adjustment_action members
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
template < typename t_target_arg, typename t_adjustment_io >
inline
t_script_simple_adjustment_action< t_target_arg, t_adjustment_io >::t_script_simple_adjustment_action()
	:	m_adjustment( 0 )
{
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
template < typename t_target_arg, typename t_adjustment_io >
inline int
t_script_simple_adjustment_action< t_target_arg, t_adjustment_io >::get_adjustment() const
{
	return m_adjustment;
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
template < typename t_target_arg, typename t_adjustment_io >
bool
t_script_simple_adjustment_action< t_target_arg, t_adjustment_io >::read_from_map(
	std::streambuf &	stream,
	int					format_version )
{
	if ( !t_script_targeted_action< t_target >::read_from_map( stream, format_version ) )
		return false;

	m_adjustment = get< t_adjustment_io >( stream );

	return true;
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
template < typename t_target_arg, typename t_adjustment_io >
bool
t_script_simple_adjustment_action< t_target_arg, t_adjustment_io >::read( std::streambuf& stream, int version )
{
	if ( !t_script_targeted_action< t_target >::read( stream, version ) )
		return false;

	m_adjustment = get< t_adjustment_io >( stream );

	return true;
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
template < typename t_target_arg, typename t_adjustment_io >
bool
t_script_simple_adjustment_action< t_target_arg, t_adjustment_io >::write( std::streambuf& stream ) const
{
	if ( !t_script_targeted_action< t_target >::write( stream ) )
		return false;

	put< t_adjustment_io >( stream, m_adjustment );
	return true;
}

#endif // !defined( SCRIPT_SIMPLE_ADJUSTMENT_ACTION_H_INCLUDED )
